package test;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTopic;

public class ProducerTopic {

	public static void main(String[] args) {
		
		String tcp = "tcp://127.0.0.1:8161" ;
		ConnectionFactory factory = new ActiveMQConnectionFactory(tcp);
		try {
			Connection conn = factory.createConnection();
			Destination topic = new ActiveMQTopic("ctopic01");
			conn.start();
			
			Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			
			MessageProducer producer = session.createProducer(topic);
			
			TextMessage message = session.createTextMessage("hahahaha");
			producer.send(message);
			
			System.out.println("ID:"+message.getJMSMessageID());
			producer.close();
			session.close();
			conn.close();
			
		} catch ( Exception e) {
			e.printStackTrace();
		}
		
		
	}

}
